package org.atovio.structure.tree;

import java.io.Serial;
import java.io.Serializable;

/**
 * Huffman树的结点类，三叉链表
 *
 * @author AtoVio, Winter Yuan
 * @version 1.0
 */
public class TriElement implements Serializable {
    @Serial
    private static final long serialVersionUID = 3L;
    // 数据域
    public int data;
    // 父母结点、左孩子和右孩子的下标
    public int parent;
    public int left;
    public int right;

    // 构造元素值为data的结点
    public TriElement(int data, int parent, int left, int right) {
        this.data = data;
        this.parent = parent;
        this.left = left;
        this.right = right;
    }

    // 构造无父母结点的叶子结点
    public TriElement(int data) {
        this.data = data;
        this.parent = -1;
        this.left = -1;
        this.right = -1;
    }

    @Override
    public String toString() {
        return this.data + "";
    }

    public boolean isLeaf(){
        return this.left == -1 && this.right ==-1;
    }
}
